<template>
  <contentModel :title="tit" @close="handleClose">
    <div>
      <commonForm
        ref="commonFormRef"
        :render-keys="renderKeys"
        :form-data="formData"
        :dis="dis"
        @loading="loadingChange"
      ></commonForm>
    </div>
    <template #footer>
      <a-space>
        <a-button v-if="btns.includes('return')" @click="emit('close')"
          >取消</a-button
        >
        <a-button
          v-if="btns.includes('save')"
          type="primary"
          :loading="okLoading"
          @click="saveForm"
          >保存</a-button
        >
      </a-space>
    </template>
  </contentModel>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import contentModel from '@/common/components/content-model/index.vue';
  import commonForm from '../components/common-form/index.vue';

  const commonFormRef = ref();
  const tit = ref('批量修改');
  const dis = ref(false);
  const formData = ref<any>({});
  const btns = ref<any[]>([]);
  const renderKeys = [
    'orderingPolicy',
    'maxPurchaseVolume',
    'procurementPreparationCycle',
    'blankingRate',
    'purchaseLeadTime',
    'inspectionConsumptionRate',
    'safetyLeadTime',
    'arrivalReceivingCycle',
    'inspectionCycle',
    'checkType',
    'minOrderQuantity',
    'quotientSelectionStrategy',
    'orderPoint',
    'categoryLv3',
    'categoryLv1',
    'categoryLv2',
    'isPhysicochemicalExperiment',
    'isNondestructiveTesting',
    'batch',
    'batchPolicy',
    'measurementMark',
  ];
  const emit = defineEmits(['close', 'save']);
  // const visible = ref(true);
  const okLoading = ref(false);
  // const handleOk = async () => {
  //   commonFormRef.value.getStatus();
  // };
  const show = (data: any, title: string, pDis: boolean, pbtns: any) => {
    formData.value = data;
    tit.value = title;
    dis.value = pDis;
    btns.value = pbtns;
  };
  const loadingChange = (val: boolean) => {
    okLoading.value = val;
  };
  const saveForm = () => {
    emit('save', { title: tit.value, data: commonFormRef.value.getStatus() });
  };
  const handleClose = () => {
    emit('close');
  };
  defineExpose({ show });
</script>
